﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import L10n.*;
    import Display.hud.*;

    public class HUDReputationComponent extends HUDComponent {

        public var m_repSliderAsset:Class;
        public var m_repSlider:HUDReputationComponent_m_repSliderAsset;
        protected var m_repPanel:JPanel;
        private var m_repHolder:JPanel;
        public var m_repText:JTextField;
        public var m_levelText:JTextField;
        private var m_socialLevel:int;

        public function HUDReputationComponent(){
            this.m_repSliderAsset = HUDReputationComponent_m_repSliderAsset;
            this.m_repSlider = (new HUDReputationComponent_m_repSliderAsset() as HUDReputationComponent_m_repSliderAsset);
            super();
            this.m_socialLevel = 1;
            var _local1:String = ((this.m_socialLevel)<10) ? ("0" + this.m_socialLevel.toString()) : this.m_socialLevel.toString();
            this.m_levelText.setText(_local1);
        }
        override protected function buildComponent():void{
            m_jPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, 0);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, true, false, false, null, null, TextFormatAlign.LEFT);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_repPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local3.setBorder(new EmptyBorder(null, new Insets(10, 10, 0, 0)));
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, 0);
            _local4.setPreferredWidth(30);
            this.m_levelText = ASwingHelper.makeTextField("0", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, 0, _local1);
            this.m_levelText.filters = [new GlowFilter(0, 0.5, 3, 3, 10)];
            _local4.append(this.m_levelText);
            _local3.append(_local4);
            _local3.append(ASwingHelper.horizontalStrut(53));
            this.m_repText = ASwingHelper.makeTextField("0", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, 0, _local1);
            this.m_repText.filters = [new GlowFilter(0, 0.5, 3, 3, 10)];
            LocaleHelper.localSetting.ASwingHelper_setEasyBorder(this.m_repText, 3, 5);
            ASwingHelper.setSizedBackground(this.m_repPanel, this.m_repSlider);
            _local3.appendAll(this.m_repText);
            this.m_repPanel.append(_local3);
            _local2.append(this.m_repPanel);
            _local2.setBorder(new EmptyBorder(null, new Insets(7)));
            m_jPanel.append(_local2);
        }
        override protected function attachToolTip():void{
            m_toolTip = new ToolTip();
            m_toolTip.attachToolTip(this);
            m_toolTip.hideCursor = true;
        }
        override public function refresh(_arg1:Boolean):void{
            super.refresh(_arg1);
            this.m_repSlider.scaleX = 1;
        }
        override protected function setCounter():void{
            m_counter = new HUDCounter(function (_arg1:Number):void{
                m_repText.setText(String(Global.player.socialXp));
                updateCounter(Global.player.socialXp);
            });
            m_counter.value = Global.player.socialXp;
            this.refresh(false);
        }
        override public function updateCounter(... _args):void{
            var _local10:Boolean;
            var _local11:int;
            var _local12:XML;
            var _local13:Number;
            var _local14:Number;
            var _local2:int = _args[0];
            var _local3:XML = Global.gameSettings.getXML();
            var _local4:XMLList = _local3.reputation.level;
            var _local5:int = this.m_socialLevel;
            var _local6:Number = 0;
            var _local7:Number = 0;
            if (_local2 > 0){
                _local10 = false;
                _local11 = _local5;
                while (_local11 < _local4.length()) {
                    _local12 = _local4[_local11];
                    _local13 = Number(_local4[(_local11 - 1)].@requiredXP);
                    _local14 = Number(_local4[_local11].@requiredXP);
                    _local7 = (_local14 - _local2);
                    _local6 = (_local7 / (_local14 - _local13));
                    if (_local12.@requiredXP <= _local2){
                        _local5 = (_local11 + 1);
                        _local10 = true;
                    } else {
                        break;
                    };
                    _local11++;
                };
            } else {
                _local5 = 1;
                _local6 = 1;
            };
            if (_local5 != this.m_socialLevel){
                this.m_socialLevel = _local5;
            };
            var _local8:MovieClip = (this.m_repSlider.sliderMask as MovieClip);
            _local8.x = ((-(_local6) * _local8.width) + 45);
            m_toolTip.toolTip = ZLoc.t("Main", "Reputation_ToolTip", {
                experience:_local7,
                level:(_local5 + 1)
            });
            var _local9:String = ((this.m_socialLevel)<10) ? ("0" + this.m_socialLevel.toString()) : this.m_socialLevel.toString();
            this.m_levelText.setText(_local9);
            this.m_repText.setText(String(_local2));
            m_counter.value = _local2;
        }

    }
}//package Display.hud.components 
